#include "OgreGLES2GpuProgram.h"
#include "OgreLogManager.h"

using namespace Ogre;

GLenum getGLShaderType(GpuProgramType programType);

GLenum getGLShaderType(GpuProgramType programType)
{
	switch(programType)
	{
	case GPT_VERTEX_PROGRAM:
	default:
		return GL_VERTEX_SHADER;
	case GPT_FRAGMENT_PROGRAM:
		return GL_FRAGMENT_SHADER;
	}
}

GLES2GpuProgram::GLES2GpuProgram(ResourceManager* creator, const String& name,
		ResourceHandle handle, const String& group, bool isManual,
		ManualResourceLoader* loader)
		: GpuProgram(creator, name, handle, group, isManual, loader)
{
	if (createParamDictionary("GLES2GpuProgram"))
	{
		setupBaseParamDictionary();
	}
}

GLES2GpuProgram::~GLES2GpuProgram()
{
	unload();
}

GLuint GLES2GpuProgram::getAttributeIndex(VertexElementSemantic semantic, uint index)
{
	return getFixedAttributeIndex(semantic, index);
}

GLuint GLES2GpuProgram::getFixedAttributeIndex(VertexElementSemantic semantic, uint index)
{
	switch(semantic)
	{
	case VES_POSITION:
		return 0;
	case VES_BLEND_WEIGHTS:
		return 1;
	case VES_NORMAL:
		return 2;
	case VES_DIFFUSE:
		return 3;
	case VES_SPECULAR:
		return 4;
	case VES_BLEND_INDICES:
		return 7;
	case VES_TEXTURE_COORDINATES:
		return 8 + index;
	case VES_TANGENT:
		return 14;
	case VES_BINORMAL:
		return 15;
	default:
		assert(false && "Missing attribute!");
		return 0;
	};
}

bool GLES2GpuProgram::isAttributeValid(VertexElementSemantic semantic, uint index)
{
	switch(semantic)
	{
	case VES_POSITION:
	case VES_NORMAL:
	case VES_DIFFUSE:
	case VES_SPECULAR:
	case VES_TEXTURE_COORDINATES:
		return false;
	case VES_BLEND_WEIGHTS:
	case VES_BLEND_INDICES:
	case VES_BINORMAL:
	case VES_TANGENT:
		return true;
	}

	return false;
}
